package com.doge;

import java.awt.Point;
import java.io.File;
import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class Tile extends Actor
{
	Main parent;
	
	//north, east, south, west
	public boolean tileEntry[] = {true, true, true, true};
	public int tileEntry_num = 0;
	//public boolean walkable = true;
	
	public boolean borderTile = false;
	
	boolean battle = false;
	public boolean occupied = false;
	
	public int x = -1;
	public int y = -1;
	
	public float pixx = -1;
	public float pixy = -1;
	public int   regionHeight = 32;
	public int   regionWidth = 32;
	
	public ArrayList<TextureRegion> textures = new ArrayList<TextureRegion>();
	
	public Character character = null;
	
	public Tile(Main parent) {
		this(parent, 0, 0);
	}
	
	public Tile(Main parent, int x, int y){
		this.parent = parent;
		this.x = x;
		this.y = y;
		//texture = parent.textures.outline;
		//textureRegion = Textures.solid;
		
	}
	
	//entering the below combination removes walkability from that direction
	//1 = north, 2 = east, 4 = south, 8 = west
	public void setCollision(int a)
	{
		tileEntry_num = a;
		if((a - 8) > -1) {  a -= 8;  tileEntry[3] = false; }
		if((a - 4) > -1) {  a -= 4;  tileEntry[2] = false; }
		if((a - 2) > -1) {  a -= 2;  tileEntry[1] = false; }
		if((a - 1) > -1) {  a -= 1;  tileEntry[0] = false; }
	}
	
	public void addTexture(TextureRegion t)
	{
		textures.add(t);
	}
	
	public Point getPosition()
	{
		return new Point((int)pixx,(int)pixy);
	}
	
	public void draw (SpriteBatch batch, float parentAlpha) 
	{
	    Color color = getColor();
	    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
	    
	    for(TextureRegion t : textures)
	    	batch.draw(t, pixx, pixy, regionWidth, regionHeight);
	    
		if(occupied)
			batch.draw(this.character.textureRegion, pixx, pixy, regionWidth, regionHeight);
	}
}
